package com.zml.control.okhttp;

import com.zml.control.ControlMainAbility;
import com.zml.control.database.PreferenceDataBase;
import ohos.hiviewdfx.HiLog;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;


public class HttpUtils {
    //1.创建OkHttpClient对象
    OkHttpClient okHttpClient = new OkHttpClient();

    public String getIAMUserToken(String url) throws IOException {
        ControlMainAbility controlMainAbility = new ControlMainAbility();
//        HuaweiCloudApi.showDeviceShadow(controlMainAbility.getContext());
        //2.创建Request对象，设置一个url地址,设置请求方式。
        Request request = new Request.Builder()
                .url(url)
                .addHeader("Content-Type", "application/json")
                .addHeader("X-Auth-Token", PreferenceDataBase.GetIAMUserToken(controlMainAbility.getContext()))
                .build();
        //3.创建一个call对象,参数就是Request请求对象
        try (Response response = okHttpClient.newCall(request).execute()) {
            return response.body().string();
        }
    };
    public String getData(String url) throws IOException {
        //2.创建Request对象，设置一个url地址,设置请求方式。
        Request request = new Request.Builder()
                .url(url)
                .addHeader("Content-Type", "application/json")
                .addHeader("X-Auth-Token", "MIITqwYJKoZIhvcNAQcCoIITnDCCE5gCAQExDTALBglghkgBZQMEAgEwghG9BgkqhkiG9w0BBwGgghGuBIIRqnsidG9rZW4iOnsiZXhwaXJlc19hdCI6IjIwMjItMTAtMDhUMTM6NTE6NDUuNDExMDAwWiIsIm1ldGhvZHMiOlsicGFzc3dvcmQiXSwiY2F0YWxvZyI6W10sInJvbGVzIjpbeyJuYW1lIjoidGVfYWRtaW4iLCJpZCI6IjAifSx7Im5hbWUiOiJ0ZV9hZ2VuY3kiLCJpZCI6IjAifSx7Im5hbWUiOiJvcF9nYXRlZF9lY3Nfc3BvdF9pbnN0YW5jZSIsImlkIjoiMCJ9LHsibmFtZSI6Im9wX2dhdGVkX2l2YXNfdmNyX3ZjYSIsImlkIjoiMCJ9LHsibmFtZSI6Im9wX2dhdGVkX2FfY24tc291dGgtNGMiLCJpZCI6IjAifSx7Im5hbWUiOiJvcF9nYXRlZF9lY3Nf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I2NjAwZjIyNzBmNGNjMDBjYzkzNjY5NDAifSwibmFtZSI6ImNuLW5vcnRoLTQiLCJpZCI6IjBjMjc4NWI5YTk4MDEwZDUyZjlkYzAwYzcwZDExNDQ1In0sImlzc3VlZF9hdCI6IjIwMjItMTAtMDdUMTM6NTE6NDUuNDExMDAwWiIsInVzZXIiOnsiZG9tYWluIjp7Im5hbWUiOiJCcmlnaHRfTUwiLCJpZCI6IjBhODcwMThiNjYwMGYyMjcwZjRjYzAwY2M5MzY2OTQwIn0sIm5hbWUiOiJCcmlnaHRfTUwiLCJwYXNzd29yZF9leHBpcmVzX2F0IjoiIiwiaWQiOiIwYTg3MDE4YzU0ODBmMjJjMWYxNmMwMGM5OTY5NDczMyJ9fX0xggHBMIIBvQIBATCBlzCBiTELMAkGA1UEBhMCQ04xEjAQBgNVBAgMCUd1YW5nRG9uZzERMA8GA1UEBwwIU2hlblpoZW4xLjAsBgNVBAoMJUh1YXdlaSBTb2Z0d2FyZSBUZWNobm9sb2dpZXMgQ28uLCBMdGQxDjAMBgNVBAsMBUNsb3VkMRMwEQYDVQQDDApjYS5pYW0ucGtpAgkA3LMrXRBhahAwCwYJYIZIAWUDBAIBMA0GCSqGSIb3DQEBAQUABIIBAIhiGcx7sU2or+nXBMFCUhvfVfxDxGqoBVsTPBpJ3of+DOXrYhYCeu+7uRy9fzfDPhvCeJwOZdX6CQTndoF82bpDYmFXedyx89+pArACv9Oc1ALfGzP7wdd2bsFRop3MAknzFgbK9dCDr2WkC-WsEOWqTHj4bJfDVCspAynjDnNjzjrz3+AF5oa46fhcMDTh8CKS2uDc3MV-twMpCK9UI01iQqBtdbuwyQHjeEtZmfSbiR1xop5EsX4yM5IP7exhU0ZksfNC62LJoTmGSIgxTGzWfVLZvqoz1qOhbaPsVImR6zUkVEoPnWIf3w3XUup4KsFNLBAJO2n-FzRlCPCovHM=")
                .build();
        //3.创建一个call对象,参数就是Request请求对象
        try (Response response = okHttpClient.newCall(request).execute()) {
            return response.body().string();
        }
    }
}
